home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus 2004 #11
/
Amiga Plus CD - 2004 - No. 11.iso
/
AmiSoft
/
Misc
/
emu
/
p-interp.lha
/
p-interp-0.5
/
rexx.c
< prev
next >
Wrap
C/C++ Source or Header
|
2002-04-25
|
3KB
|
95 lines
/*
** C2Rexx.c -- by Bryan Ewert -- 02 Jun 1996
** Amiga Users of Calgary OOPSIG -- Calgary, Alberta, Canada
**
** Sends the ARexx command "EXECUTE" to p-interp's
** Rexx port "TURTLESERVER"
*/
/*
** Based on code in:
**
** fancydemo.c - A fancy rexx host that can send and receive messages.
** Author - Gary Samad & Bill Hawes
** This is truly Public Domain!!
*/
#include "rexx.h"
/******** This is the REXX stuff ********/
struct MsgPort *setup_rexx_port(void)
{
struct MsgPort *the_port;
return FindPort(TURTLE_HOST_NAME);
/* Disable multitasking so a port won't (dis)appear unexpectedly */
Forbid();
/* look for someone else that looks just like us! */
if (FindPort(HOST_PORT_NAME))
{
Permit();
printf("A public port called '%s' already exists!\n",HOST_PORT_NAME);
return(NULL);
}
/* allocate the port */
the_port = CreatePort(HOST_PORT_NAME,0L);
/* We're done here -- re-enable multitasking */
Permit();
/* Inform the application of our new port */
return(the_port);
}
void shutdown_rexx_port(struct MsgPort *rexx_port)
{
DeletePort(rexx_port);
}
int send_rexx_command(char *buff)
{
struct MsgPort *rexxport; /* this will be rexx's port */
struct RexxMsg *rexx_command_message; /* this is the message */
/* lock things temporarily */
Forbid();
/* if rexx is not active, just return NOTOK */
if ((rexxport = FindPort(TURTLE_HOST_NAME)) == NULL)
{
Permit();
return(NOTOK);
}
/* allocate a message packet for our command */
/* note that this is a very important call. Much flexibility is */
/* available to you here by using multiple host port names, etc. */
if (NULL == (rexx_command_message = CreateRexxMsg(rexx_port,
REXX_EXTENSION, rexx_port->mp_Node.ln_Name)))
{
Permit();
return(NOTOK);
}
/* create an argument string and install it in the message */
if (NULL == (rexx_command_message->rm_Args[0] = CreateArgstring(buff,
strlen(buff))))
{
DeleteRexxMsg(rexx_command_message);
Permit();
return(NOTOK);
}
/* tell rexx that this is a COMMAND, not a FUNCTION, etc. */
rexx_command_message->rm_Action = RXCOMM;
/* and now the EASY part! */
PutMsg(rexxport, (struct Message *) rexx_command_message);
/* we're done hogging */
Permit();
printf("Message sent:\n");
printf("CommAddr: %s\n", rexx_command_message->rm_CommAddr);
printf("FileExt: %s\n", rexx_command_message->rm_FileExt);
printf("Arg: %s\n", rexx_command_message->rm_Args[0]);
/* successful, finally... */
return(OK);
}
void free_rexx_command(struct RexxMsg *rexxmessage)
{
/* delete the argument that we originally sent */
DeleteArgstring(rexxmessage->rm_Args[0]);
/* delete the extended message */
DeleteRexxMsg(rexxmessage);
}